module.exports = function ($resource, $state, $http, $q, $scope, FileUploader, $modal, toaster, $stateParams, date2str) {
    /* 分页
  * ========================================= */
  $scope.maxSize = 5;             //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10         //每页显示几条
  $scope.obj={};
  $scope.d={};
  $scope.searchform = {};
  $scope.vm = {
      'date' : '',
      'options' : {
          format: "YYYY-MM-DD",
          locale : 'zh-cn'
      }
  }
  $scope.vm1 = {
      'date' : '',
      'options' : {
          format: "YYYY-MM-DD",
          locale : 'zh-cn'
      }
  }
  console.log($state.params.type);
  if ($stateParams.type == '0'){
      $resource('/api/ac/ggc/reviewCompanyService/getApplyCompanyInfo', {}, {}).save({}, function(res){
          if(res.errcode != 0){ 
              toaster.error({title:"",body:res.errmsg});
              return;
          }
          console.log('查询企业信息是否完整');
          console.log(res);
          if (res.data.msg == '0') {
            if (confirm('请先完善企业信息')) {
              $state.go('app.completeinfo');
            } else {
              $state.go('app.completeinfo');
            }
          }
      });
  }
  $scope.info = {
      'start_time' : '',
      'end_time' : ''
  }
  $scope.pageChanged = function () {
      if ($scope.vm.date._d == undefined) {
          $scope.info.start_time = '';
      } else {
        $scope.info.start_time = date2str($scope.vm.date._d);
      }
      if ($scope.vm1.date._d == undefined) {
          $scope.info.end_time = '';
      } else {
          $scope.info.end_time = date2str($scope.vm1.date._d);
      }
      console.log(($scope.vm.date._d));
      var para = {
          pageNo:$scope.bigCurrentPage,
          pageSize:$scope.itemsPerPage
      };
      para = angular.extend($scope.searchform, para, $scope.info);
      if($state.params.type == 0) {
        console.log('这是0')
        $resource('/api/ac/ggc/reviewCompanyProjectService/findInfoList', {}, {}).save(para, function(res){	
            if(res.errcode === 0 || res.errcode === 10003){
                $scope.a = res.data.results;
                console.log($scope.a);
                console.log('上面是企业项目列表返回值') 
                $scope.bigTotalItems = res.data.totalRecord;
                // angular.forEach ($scope.a,function(item,index){
                //     // console.log(item.project_build);
                //     item.process = '项目已提报' + item.apply_time;
                    
                //     console.log(item.project_state + '-' + item.recommend_district + '-' + item.recommend_city + '-'+ item.planning_state + '-' + item.director_agree)
                //     if (item.project_state == '5' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '1' && item.director_agree == '2' ) {
                //         if (item.city_project == '0'){
                //             item.process = '<p>' + item.process + '<br>' + ';' + '</p>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time + '<br>' + '委主任办公会审核通过' + item.director_agree_time
                //         }
                //         if (item.city_project == '1'){
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time + '<br>' + '委主任办公会审核通过' + item.director_agree_time
                //         }
                //     }
                //     if (item.project_state == '5' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '1' && item.director_agree == '1') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time + '<br>' + '委主任办公会审核未通过' + item.director_agree_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time + '<br>' + '委主任办公会审核未通过' + item.director_agree_time
                //         }
                //     }
                //     if (item.project_state == '5' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '1' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time 
                //         }
                //     }
                //     if (item.project_state == '2' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '2' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核驳回' + item.planning_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核驳回' + item.planning_time 
                //         }    
                //     }
                //     if (item.project_state == '4' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '3' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核淘汰' + item.planning_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核淘汰' + item.planning_time 
                //         }    
                //     }
                //     if (item.project_state == '3' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '0' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time 
                //         }
                //     }
                //     if (item.project_state == '2' && item.recommend_district == '1' && item.recommend_city == '2' && item.planning_state == '0' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核驳回' + item.examine_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核驳回' + item.examine_time 
                //         }
                //     }
                //     if (item.project_state == '4' && item.recommend_district == '1' && item.recommend_city == '3' && item.planning_state == '0' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核淘汰' + item.examine_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核淘汰' + item.examine_time 
                //         }
                //     }
                    
                //     if (item.city_project == '0' && item.project_state == '1' && item.recommend_district == '1' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time
                //     }
                //     if (item.city_project == '0' && item.project_state == '2' && item.recommend_district == '2' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = item.process + '<br>' + item.company_code_name + '审核驳回' + item.recommend_district_time
                //     }
                //     if (item.city_project == '0' && item.project_state == '4' && item.recommend_district == '3' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = item.process + '<br>' + item.company_code_name + '审核淘汰' + item.recommend_district_time
                //     }
                //     if (item.city_project == '1' && item.project_state == '1' && item.recommend_district == '1' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = item.process ;
                //     }
                //     if (item.project_state == '0' && item.recommend_district == '0' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = '撤回编辑中' 
                //     }
                //     console.log(item.process);
                //     if (item.apply_time == undefined) {
                //         item.process = '撤回编辑中'
                //     }
                //     if(item.city_project == '0') {
                //         item.city_project = '否'
                //     }
                //     if(item.city_project == '1') {
                //         item.city_project = '是'
                //     }
                // }) 
            }else{
                alert(res.errmsg);
            }
        });
    } else {
        console.log('这是1')
        $resource('/api/ac/ggc/reviewCompanyProjectService/findInfoByAdminList', {}, {}).save(para, function(res){	
            if(res.errcode === 0 || res.errcode === 10003){
                $scope.a=res.data.results;
                $scope.bigTotalItems = res.data.totalRecord;					
                console.log($scope.a);
                console.log('上面是企业项目列表返回值') 
                // angular.forEach ($scope.a,function(item,index){
                //     // console.log(item.project_build);
                //     item.process = '项目已提报' + '-' + item.apply_time;
                    
                //     console.log(item.project_state + '-' + item.recommend_district + '-' + item.recommend_city + '-'+ item.planning_state + '-' + item.director_agree)
                //     if (item.project_state == '5' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '1' && item.director_agree == '2' ) {
                //         if (item.city_project == '0'){
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time + '<br>' + '委主任办公会审核通过' + item.director_agree_time
                //         }
                //         if (item.city_project == '1'){
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time + '<br>' + '委主任办公会审核通过' + item.director_agree_time
                //         }
                //     }
                //     if (item.project_state == '5' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '1' && item.director_agree == '1') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time + '<br>' + '委主任办公会审核未通过' + item.director_agree_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time + '<br>' + '委主任办公会审核未通过' + item.director_agree_time
                //         }
                //     }
                //     if (item.project_state == '5' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '1' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核通过' + item.planning_time 
                //         }
                //     }
                //     if (item.project_state == '2' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '2' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核驳回' + item.planning_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核驳回' + item.planning_time 
                //         }    
                //     }
                //     if (item.project_state == '4' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '3' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核淘汰' + item.planning_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time + '<br>' +'项目复核淘汰' + item.planning_time 
                //         }    
                //     }
                //     if (item.project_state == '3' && item.recommend_district == '1' && item.recommend_city == '1' && item.planning_state == '0' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核通过' + item.examine_time 
                //         }
                //     }
                //     if (item.project_state == '2' && item.recommend_district == '1' && item.recommend_city == '2' && item.planning_state == '0' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核驳回' + item.examine_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核驳回' + item.examine_time 
                //         }
                //     }
                //     if (item.project_state == '4' && item.recommend_district == '1' && item.recommend_city == '3' && item.planning_state == '0' && item.director_agree == '0') {
                //         if (item.city_project == '0') {
                //             item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time + '<br>' + item.recommend_type_name +'审核淘汰' + item.examine_time
                //         }
                //         if (item.city_project == '1') {
                //             item.process = item.process + '<br>' + item.recommend_type_name +'审核淘汰' + item.examine_time 
                //         }
                //     }
                    
                //     if (item.city_project == '0' && item.project_state == '1' && item.recommend_district == '1' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = item.process + '<br>' + item.company_code_name + '审核通过' + item.recommend_district_time
                //     }
                //     if (item.city_project == '0' && item.project_state == '2' && item.recommend_district == '2' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = item.process + '<br>' + item.company_code_name + '审核驳回' + item.recommend_district_time
                //     }
                //     if (item.city_project == '0' && item.project_state == '4' && item.recommend_district == '3' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = item.process + '<br>' + item.company_code_name + '审核淘汰' + item.recommend_district_time
                //     }
                //     if (item.city_project == '1' && item.project_state == '1' && item.recommend_district == '1' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = item.process ;
                //     }
                //     if (item.project_state == '0' && item.recommend_district == '0' && item.recommend_city == '0' && item.planning_state == '0' && item.director_agree == '0' ) {
                //         item.process = '撤回编辑中' 
                //     }
                //     console.log(item.process);
                //     if (item.apply_time == undefined) {
                //         item.process = '撤回编辑中'
                //     }
                //     if(item.city_project == '0') {
                //         item.city_project = '否'
                //     }
                //     if(item.city_project == '1') {
                //         item.city_project = '是'
                //     }
                // })      
            }else{
                alert(res.errmsg);
            }
        });
    }
      
  };
  $scope.pageChanged();

  $scope.search=function(){
      var dic = {
          pageNo:$scope.currentPage,
          pageSize:$scope.itemsPerPage,
      }
      $resource('', {}, {}).save(dic, function(res){
          if(res.errcode === 0 || res.errcode === 10003){
              $scope.a=res.data.results;
              console.log($scope.a);
              $scope.totalItems = res.data.totalRecord;
          }else{
              alert(res.errmsg);
          }
      });
  }

  $scope.toinfo= function (info) {
    if ($stateParams.type == '1'){
      $scope.type = 'gfonlyinfo';	
      var modalInstance = $modal.open({
        template: require('../views/project_search_info.html'),
        controller: 'project_search_info',
        size: 'lg',
        resolve: {
          items: function () {
            return info;
          },
          type: function () {
            return $scope.type;
          }
        }
      });
      modalInstance.result.then(function (showResult) {	
          $scope.pageChanged();
      });
    } else if ($stateParams.type == '0'){
      $scope.type = 'qyonlyinfo';	
      var modalInstance = $modal.open({
        template: require('../views/project_search_info.html'),
        controller: 'project_search_info',
        size: 'lg',
        resolve: {
          items: function () {
            return info;
          },
          type: function () {
            return $scope.type;
          }
        }
      });
      modalInstance.result.then(function (showResult) {	
          $scope.pageChanged();
      });
    }
  }


  $scope.progress= function (index) {
      $scope.item = $scope.a[index];			
      var modalInstance = $modal.open({
        template: require('../views/project_progress.html'),
        controller: 'project_progress',
        size: 'lg',
        resolve: {
          items: function () {
            return $scope.item;
          },
          type: function () {
            return $stateParams.type;
          }
        }
      });
      modalInstance.result.then(function (showResult) {	
          $scope.pageChanged();
      });
  }

  // 监听
//   $scope.$watch('productflag', function(){
//     $scope.pageChanged();
//   }, true)

}
	